home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / comm / mail / thor201.lha / THOR_2.0 / thor.lha / rexx / UUDecode.thor < prev    next >
Text File  |  1995-05-15  |  6KB  |  226 lines

  1. /* UUDecode.thor by Troels Walsted Hansen
  2. ** $VER: UUDecode.thor v2.20 (14.05.95)
  3. **
  4. ** An ARexx script that uudecodes the file(s) contained in the
  5. ** message currently displayed in THOR. Can also be used from the 
  6. ** commandline with one single argument, the name of the uu-message.
  7. **
  8. ** Either of the following uudecoders may be used:
  9. **      · UUFast v1.25 by Jørn Halonen
  10. **      · uuOut v1.03 by Nicolas Dade.
  11. **      · UUxT v3.0 by Asher Feldman
  12. ** ...or you may define one for yourself.
  13. **
  14. ** HISTORY
  15. ** ¯¯¯¯¯¯¯
  16. ** UUDecode.thor v2.00 (20.11.94)
  17. **      · This version is only for THOR v2.0 or higher.
  18. **      · A lot easier to adapt to other uudecoders and
  19. **        includes commandstrings for uuOut, UUFast and UUxT.
  20. **      · Finally fixed qoutes around downloadpath with spaces.
  21. **        (Thank you Sigbjørn Skjæret! :)
  22. **      · Doesn't require rexxsupport.library anymore.
  23. **      · adds comments to uudecoded files containing
  24. **        'From <name> in <conf> on <bbsname>'.
  25. **
  26. ** UUDecode.thor v2.05 (07.12.94)
  27. **      · adds filenotes to *all* files in the message
  28. **
  29. ** UUDecode.thor v2.10 (19.03.95)
  30. **      · filenote adding is optional
  31. **      · specifies MSGNR instead of SAVEMESSAGE'ing CURRENT
  32. **      · may be used from the commandline
  33. **      · now shows errormsg from uudecoders if something went wrong
  34. **        (All suggested by Eirik Synnes)
  35. **
  36. ** UUDecode.thor v2.15 (25.03.95)
  37. **      · now locks the gui whilst saving
  38. **      · improved find-filename-so-we-can-add-filenote code
  39. **
  40. ** UUDecode.thor v2.16 (11.05.95)
  41. **      · forgot to delete a tmpfile
  42. **
  43. ** UUDecode.thor v2.20 (14.05.95)
  44. **      · won't READBRMESSAGE if filenote adding  is disabled
  45. */
  46.  
  47. /* some user variables. edit to your hearts content */
  48.  
  49. tmpdir = "T:"        /* Work dir for the decoding        */
  50. uudecoder = "uuout"    /* may be: uuout, uufast or uuxt    */
  51. filenotes = "no"    /* Add filenotes? "yes" or "no"        */
  52.  
  53. /* needs THOR and bbsread.library functions */
  54.  
  55. options results
  56. options failat 31    /* otherwise the output window may pop up all the time */
  57.  
  58. p = address() || ' ' || show('P',,)
  59. thorport = pos('THOR.',p)
  60.  
  61. if thorport > 0 then thorport = word(substr(p,thorport),1)
  62. else
  63. do
  64.     say 'No THOR port found!'
  65.     exit 10
  66. end
  67.  
  68. if ~show('p', 'BBSREAD') then
  69. do
  70.     address command
  71.         "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
  72.         "WaitForPort BBSREAD"
  73. end
  74.  
  75. /* the download dir needs to be obtained from THOR no matter what */
  76.  
  77. address(bbsread)
  78. GETGLOBALDATA STEM GLOBALDATA
  79. if(rc ~= 0) then
  80. do
  81.     address(thorport)
  82.     REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
  83.     exit
  84. end
  85.  
  86. endchar = right(GLOBALDATA.DNLOADPATH, 1)
  87. if(endchar ~= ":" & endchar ~= "/") then GLOBALDATA.DNLOADPATH = GLOBALDATA.DNLOADPATH || '/'
  88.  
  89. /* if we got a filename on the commandline, half the script may be skipped */
  90.  
  91. parse arg msgfilename
  92. if(msgfilename ~= '') then
  93. do
  94.     filenotes = 'no'
  95.     signal commandline
  96. end
  97.  
  98. /* no, we're not started from the commandline */
  99.  
  100. msgfilename = tmpdir || 'Message.uu'
  101.  
  102. /* lock the gui till we've saved the message */
  103.  
  104. address(thorport)
  105. LOCKGUI
  106.  
  107. /* look for 'begin xxx filename' lines, so we can add a filenote later */
  108.  
  109. if(filenotes = "yes") then
  110. do
  111.     address(thorport)
  112.     CURRENTMSG stem MSG
  113.     if(rc ~= 0) then
  114.     do
  115.         address(thorport)
  116.         REQUESTNOTIFY TEXT '"'THOR.LASTERROR'"' BT '"_Ok"'
  117.         signal exit
  118.     end
  119.  
  120.     address(bbsread)
  121.     READBRMESSAGE BBSNAME '"'MSG.BBSNAME'"' CONFNAME '"'MSG.CONFNAME'"' MSGNR MSG.MSGNR headstem HEADTAGS textstem TEXTTAGS
  122.     if(rc ~= 0) then
  123.     do
  124.         address(thorport)
  125.         REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
  126.         signal exit
  127.     end
  128.  
  129.     filenamecount = 1
  130.  
  131.     do i=1 to TEXTTAGS.TEXT.COUNT
  132.         if(left(TEXTTAGS.TEXT.i, 5) = 'begin') then
  133.         do
  134.             realfilename.filenamecount = substr(TEXTTAGS.TEXT.i, wordindex(TEXTTAGS.TEXT.i, 3))
  135.             posi2 = 0
  136.  
  137.             posi = pos(':', realfilename.filenamecount)
  138.             if(posi ~= 0) then posi2 = posi
  139.  
  140.             posi = lastpos('/', realfilename.filenamecount)
  141.             if(posi ~= 0) then posi2 = posi
  142.  
  143.             if(posi2 ~= 0) then realfilename.filenamecount = substr(realfilename.filenamecount, posi2+1)
  144.  
  145.             filenamecount = filenamecount+1
  146.         end
  147.     end
  148. end
  149.  
  150. /* save the message to a tmp file */
  151.  
  152. address(thorport)
  153. SAVEMESSAGE CURRENT FILENAME msgfilename NOHEADER NOANSI
  154. if(rc ~= 0) then
  155. do
  156.     address(thorport)
  157.     REQUESTNOTIFY TEXT '"'THOR.LASTERROR'"' BT '"_Ok"'
  158.     signal exit
  159. end
  160.  
  161. /* unlock the gui */
  162.  
  163. address(thorport)
  164. UNLOCKGUI
  165.  
  166. /* label that specifies where to jump if we're started from the commandline */
  167.  
  168. commandline:
  169.  
  170. if ~exists(msgfilename) then
  171. do
  172.     address(thorport)
  173.     REQUESTNOTIFY TEXT '"Message containing uuencoded file not found."' BT '"_Ok"'
  174.     exit
  175. end
  176.  
  177. tmpfile = tmpdir || 'uudecoder.output'
  178.  
  179. select
  180.     when(uudecoder = 'uufast')    then cmd = 'UUFast >' || tmpfile || ' ' || msgfilename || ' TO "' || GLOBALDATA.DNLOADPATH || '"'
  181.     when(uudecoder = 'uuout')    then cmd = 'uuOut >' || tmpfile || ' ' || msgfilename || ' OUTPATH="' || GLOBALDATA.DNLOADPATH || '" USEBASENAME'
  182.     when(uudecoder = 'uuxt')    then cmd = 'UUxT >' || tmpfile || ' x ' || msgfilename || ' dest=' || GLOBALDATA.DNLOADPATH
  183.     otherwise
  184.     do
  185.         address(thorport)
  186.         REQUESTNOTIFY TEXT '"UUDecoder not configured correctly."' BT '"_Ok"'
  187.         signal exit
  188.     end
  189. end
  190.  
  191. address command cmd
  192. if(rc ~= 0) then
  193. do
  194.     call open(tmpfh, tmpfile, R)
  195.     errormsg = ''
  196.  
  197.     do forever
  198.         str = readln(tmpfh)
  199.         if(str = '') then break
  200.         else errormsg = errormsg || '\n' || str
  201.     end
  202.  
  203.     call close(tmpfh)
  204.  
  205.     errormsg = 'UUDecoding did not succeed.' || errormsg
  206.  
  207.     address(thorport)
  208.     REQUESTNOTIFY TEXT '"'errormsg'"' BT '"_Ok"'
  209. end
  210. else if(filenotes = "yes") then
  211. do
  212.     do j=1 to (filenamecount-1)
  213.         address command 'filenote ' || '"' || GLOBALDATA.DNLOADPATH || realfilename.j || '"' || ' ' || '"' || 'From ' || HEADTAGS.FROMNAME || ' in ' || MSG.CONFNAME || ' on ' || MSG.BBSNAME || '"' || ' QUIET'
  214.     end
  215. end
  216.  
  217. /* cleanup and exit */
  218.  
  219. exit:
  220.     address(thorport)
  221.     UNLOCKGUI
  222.  
  223.     address command "delete >nil: "msgfilename
  224.     address command "delete >nil: "tmpfile
  225.     exit
  226.